home *** CD-ROM | disk | FTP | other *** search
- #include "rexxhostbase.h"
- #include <stdio.h>
- #include "mb.h"
-
- struct RexxHostBase *RexxHostBase;
-
- extern char optflags[];
- struct RexxHost *rexx_host;
- struct MsgPort *non_rexx = 0L;
- long rexxbit = 0L;
- extern char tmpstr[];
- char *portname = "CBBS-A";
- extern char hostport;
- /* Try to open the rexxhost.library. Option G (6) turns REXX off */
- open_rexx()
- {
-
- portname[5] = hostport;
- if(!optflags[6]) {
- non_rexx = CreatePort((UBYTE *)portname,0L);
- return(0);
- }
- if(!(RexxHostBase = (struct RexxHostBase *)
- OpenLibrary((UBYTE *)REXXHOSTNAME,(long)REXXHOSTMINIMUM))) {
- printf("couldn't open rexxhost library.\n");
- return(1);
- }
-
- /* set up a public port for rexx to talk to us later */
-
- if(!(rexx_host = CreateRexxHost((STRPTR)portname))) {
- printf("Can't set up public rexx port for port %c\n",hostport);
- CloseLibrary((struct Library *)RexxHostBase);
- return(1);
- }
- rexxbit = (1L << rexx_host->rh_Port.mp_SigBit);
- return(0);
- }
- close_rexx()
- {
- struct RexxMsg *rexxmessage; /* incoming rexx messages */
- STRPTR Arg;
-
- if(!optflags[6]) {
- DeletePort(non_rexx);
- return;
- }
- /* Drain any messages for us */
- while(rexxmessage = GetRexxMsg(rexx_host,0L)) {
- if(Arg = GetRexxCommand(rexxmessage)) {
- ReplyRexxCommand(rexxmessage,0L,0L,0L);
- }
- else {
- FreeRexxCommand(rexxmessage);
- }
- }
- if(rexx_host)
- rexx_host = DeleteRexxHost(rexx_host);
-
- if(RexxHostBase)
- CloseLibrary((struct Library *)RexxHostBase);
- }
- testport()
- {
- if(!optflags[6])return;
- portname[5] = hostport;
- if(FindPort((UBYTE *)portname)) {
- printf("There's already a process on port '%c'\n",hostport);
- return(1);
- }
- return(0);
- }
-
- /* This routine can only be called from SYSOP. */
- putcomd(a,b)
- char a,b;
- {
- char data[3];
- STRPTR rexxname;
- char portchar;
- register PORTS *p;
-
- if(!optflags[6])return;
- /* Do AI - forward on all ports.
- a and b are the A command changed to an X .. eg AI will be input as XI
- */
- if((b == ' ') || (b == 'I')) {
- for(p = porthd; p isnt NULL; p = p->next) {
- if(p->id == 'Z')continue;
- rexxname = (STRPTR)"CBBS-A";
- rexxname[5] = p->id;
- data[0] = a;
- data[1] = b;
- data[2] = 0;
- if(SendRexxMsg(rexxname,0L,(STRPTR)data,1L) == 0) {
- sprintf(tmpstr,"Can't find port %c\n",p->id);
- ttputs(tmpstr);
- }
- }
- return;
- }
- portchar = 0;
- if(isdigit(b)) {
- portchar = b ^ 0x70;
- b = ' ';
- }
- else {
- if(isalpha(b)) {
- portchar = toupper(b);
- b = 'I';
- }
- }
- if((portchar == 0) || ((portchar < 'A') && (portchar > 'P'))) {
- ttputs("Unrecognized port\n");
- return;
- }
- rexxname = (STRPTR)"CBBS-A";
- rexxname[5] = portchar;
- data[0] = a;
- data[1] = b;
- data[2] = 0;
- if(SendRexxMsg(rexxname,0L,(STRPTR)data,1L))return;
- sprintf(tmpstr,"Can't find port %c\n",portchar);
- ttputs(tmpstr);
- }
-